package gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Login {

	Shell shell;
	Display display;
	Label label1, label2;
	Text enfermero;
	
	Text text;
	private boolean ok = false;
	private int enfermeroId;
	private String nombreEnfermero;
	private String apellidoEnfermero;

	public String getApellidoEnfermero() {
		return apellidoEnfermero;
	}

	public void setApellidoEnfermero(String apellidoEnfermero) {
		this.apellidoEnfermero = apellidoEnfermero;
	}

	public boolean isOk() {
		return ok;
	}

	public String getNombreEnfermero() {
		return nombreEnfermero;
	}

	public void setNombreEnfermero(String nombreEnfermero) {
		
		this.nombreEnfermero = nombreEnfermero;
	}

	public void setOk(boolean ok) {
		this.ok = ok;
	}

	public int getEnfermeroId() {
		return enfermeroId;
	}

	public void setEnfermeroId(int enfermeroId) {
		this.enfermeroId = enfermeroId;
	}

	public Login(Display display2) {	
		this.shell = new Shell(display2);
		this.display = display2;
		GridLayout gl = new GridLayout(5, false);
		
		shell.setLayout(gl);
		
		shell.setText("Ingreso a SAER");
		label1 = new Label(shell, SWT.NULL);
		label1.setText("Enfermero: ");

		enfermero = new Text(shell, SWT.SINGLE | SWT.BORDER);
		enfermero.setText("");
		enfermero.setTextLimit(30);

//		label2 = new Label(shell, SWT.NULL);
//		label2.setText("Password: ");

//		password = new Text(shell, SWT.SINGLE | SWT.BORDER);
//		System.out.println(password.getEchoChar());
//		password.setEchoChar('*');
//		password.setTextLimit(30);

		Button button = new Button(shell, SWT.PUSH);
		button.setText("Ingresar");
		button.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				String selected = enfermero.getText();
			//	String selected1 = password.getText();

				if (selected == "") {
					MessageBox messageBox = new MessageBox(shell, SWT.OK
							| SWT.ICON_WARNING | SWT.CANCEL);
					messageBox.setMessage("Ingrese el Enfermero");
					messageBox.open();
				}
//				if (selected1 == "") {
//					MessageBox messageBox = new MessageBox(shell, SWT.OK
//							| SWT.ICON_WARNING | SWT.CANCEL);
//					messageBox.setMessage("Enter the Password");
//					// messageBox.open();
//				} 
				else {
//					MessageBox messageBox = new MessageBox(shell, SWT.OK
//							| SWT.CANCEL);
//					messageBox.setText("SAER");
//					messageBox.setMessage("Bienvenido:" + username.getText());
//					messageBox.open();
					ok = true;
					enfermeroId = Integer.parseInt(enfermero.getText());
					nombreEnfermero = "Rodrigo";
					apellidoEnfermero = "Girlando";
					shell.close();
				}
			}
		});
		
		enfermero.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	//	password.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		shell.setLocation(500, 300);
		shell.pack();
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	//	display.dispose();
	}
//	 public static void main(String[] args) {
//		 new Login();
//	 }
}